package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.DynamicComment;
import cn.wolfcode.trip.base.domain.UserDynamic;
import cn.wolfcode.trip.base.mapper.DynamicCommentMapper;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.query.UserQueryObject;
import cn.wolfcode.trip.base.service.IArticleCommentService;
import cn.wolfcode.trip.base.service.IUserDynamicService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/userDynamics")
public class UserDynamicController {
    @Autowired
    private IUserDynamicService dynamicService;
    @Autowired
    private DynamicCommentMapper commentMapper;

    /**
     * 查询当前用户所关注的人发布的动态 按发布时间降序排列
     */
    @GetMapping("/{userId}")
    public List<UserDynamic> queryCommends(@PathVariable Long userId) {
        List<UserDynamic> userDynamics = dynamicService.queryByUserDynamics(userId);
        for(UserDynamic dynamic:userDynamics){
            List<DynamicComment> commentList = commentMapper.ListForDynamicID(dynamic.getId());
            dynamic.setCommentList(commentList);
        }
        return userDynamics;
    }

    @GetMapping("commend/{commentId}")
    public List listCommends(@PathVariable Long commentId) {
        List<DynamicComment> commentList = commentMapper.ListForDynamicID(commentId);
        return commentList;
    }
}
